package com.lock;

public class Testlock {

    public static void main(String [] args)
    {

        //data();
        //datacondition();
        //dataconditonOrder();
        dataLockReadWrite();

    }

    /***
     * synchronize
     */
    static void data()
    {
        final DataSynchronize data=new DataSynchronize();
        new Thread(new Runnable() {
            public void run() {
                for(int i=0;i<1000000000;i++)
                {
                    data.write();

                }
            }
        }).start();

        new Thread(new Runnable() {
            public void run() {
                for(int i=0;i<1000000000;i++)
                {
                    data.get();

                }
            }
        }).start();
    }

    /**
     * lock+condition
     */
    static void  datacondition()
    {
        final DataLockcondition data=new DataLockcondition();

        new Thread(new Runnable() {
            public void run() {
                for(int i=0;i<1000000000;i++)
                {
                    data.write();

                }
            }
        }).start();

        new Thread(new Runnable() {
            public void run() {
                for(int i=0;i<1000000000;i++)
                {
                    data.get();

                }
            }
        }).start();
    }

    /**
     * lock+condition+order
     */
    static void dataconditonOrder()
    {
        final DataLockConditonOrder lockConditonOrder=new DataLockConditonOrder();
        new Thread(new Runnable() {
            public void run() {
                for (int i=0;i<10;i++)
                {
                    lockConditonOrder.main(i);
                }
            }
        }).start();

        new Thread(new Runnable() {
            public void run() {
                for (int i=0;i<10;i++)
                {
                    lockConditonOrder.sub1(i);
                }
            }
        }).start();

        for (int i=0;i<10;i++)
        {
            lockConditonOrder.sub2(i);
        }
    }


    /**
     * lockReadwrite
     */
    static void dataLockReadWrite()
    {
        final DataLockReadwrite data=new DataLockReadwrite();

        for (int i=0;i<3;i++) {
            new Thread(new Runnable() {
                public void run() {
                        data.write();
                }
            }).start();
        }

        for (int i=0;i<3;i++){
            new Thread(new Runnable() {
                public void run() {
                        data.get();
                }
            }).start();
        }

    }

}
